#include "rapidjson/serialize.hpp"
#include "rapidjson/deserialize.hpp"
#include <iostream>

struct BigEndUint64Bits {
	uint64_t data = 0;
	//如果需要定制反序列化就实现
	void deserialize(const rapidjson::Value &root)
	{
		if (root.IsArray()) {
            auto arr = root.GetArray();
            data = 0;
            for (auto &it : arr) {
            	if (it.IsUint()) {
		            auto v = it.GetUint();
		            if (v > 0 && v <= 64) {
		            	data |= (1ULL << (56 - ((v - 1) & 0xf8) + ((v - 1) & 0x7)));
		            }
		        }
            }
		}
	}
	//如果需要定制序列化就实现
	void serialize(rapidjson::StdStringWriter &writer) const
	{
		writer.StartArray();
		for (int i = 0; i < 64; i++) {
			if ((data & (1ULL << i)) > 0) {
				writer.Int(57 - (i & 0xf8) + (i & 0x7));
			}
		}
        writer.EndArray();
	}
	//如果需要强制转换就实现
	explicit operator uint64_t() { return data; }
};

int main()
{
	BigEndUint64Bits v, x;
	v.data = 1ULL << 56;
	auto str = rapidjson::serialize(v);
	std::cout << str << std::endl;
	std::string err;
	if (rapidjson::deserialize(x, str, err)) {
		std::cout << (x.data == v.data) << std::endl;
	} else {
		std::cout << err << std::endl;
	}
	return 0;
}